package com.hna.eking.AirlineServer.Mapper;

import java.util.Date;
import java.util.List;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.Update;
@Mapper
public interface AirportInfoMapper {
//    int insert(AirportInfo record);
//
//    int insertSelective(AirportInfo record);
//
//    AirportInfo selectByPrimaryKey(String airportCode);
//
//    int updateByPrimaryKeySelective(AirportInfo record);
//
//    int updateByPrimaryKey(AirportInfo record);
    
    @Select("SELECT airport_code, map_version FROM t_airport_info WHERE airport_code = #{0} and map_version > #{1} and effect_flag='0001'")
    public AirportInfo selectByAirportCodeAndMapVersion(String airportCode, Integer mapVersion);
    
    @Select("SELECT * FROM t_airport_info WHERE airport_version > #{1} and effect_flag='0001'")
    public List<AirportInfo> selectByAirportVersion(Integer airportVersion);
    
    @Select("SELECT * FROM t_airport_info")
    public List<AirportInfo> selectAll();
    
    @Select("SELECT * FROM t_airport_info where effect_flag = '0001' ")
    public List<AirportInfo> selectAllEfft();
    
    @Select("SELECT * FROM t_airport_info WHERE airport_code = #{0}")
    public AirportInfo selectByArptNo(String airportCode);
    
    @Update("update t_airport_info set map_version = map_version + 1,"
    		+ "update_date =#{1}, update_user=#{2}"
    		+ " where airport_code = #{0}")
    public int updateAirportMapVersion(String airportCode, java.util.Date upDate, String user);
    
    @Select("SELECT map_version FROM t_airport_info WHERE airport_code = #{0}")
    Integer selectMapVersion(String airportCode);
    
    @Update("update t_airport_info set airport_name=#{airportName},"
			+ "short_name=#{shortName},english_name=#{englishName},"
			+ "short_name_en=#{shortNameEn},atis=#{atis},country=#{country},"
			+ "province=#{province},city=#{city},"
			+ "airport_version=airport_version + 1,"
			+ "update_date=#{updateDate},update_user=#{updateUser}"
			+ "where airport_code=#{airportCode}")
    public int updateAirportByKey(AirportInfo airportinfo);
    
    @Insert("INSERT INTO t_airport_info(airport_code,airport_name,short_name,english_name,short_name_en, atis,country,"
    		+ "province,city,"
			+ "create_date,create_user,update_date,update_user,effect_flag)"
			+ "VALUES(#{airportCode},#{airportName},#{shortName},#{englishName},#{shortNameEn},"
			+ "#{atis},#{country},#{province},#{city},"
			+ "#{createDate},#{createUser},#{updateDate},"
			+ "#{updateUser},#{effectFlag})")
	public void InsertAirportInfo(AirportInfo airportinfo);
    
    @Update("update t_airport_info set effect_flag = '0000', update_user = #{1},update_date = #{2},"
			+ "airport_version = airport_version + 1 , map_version = map_version + 1 "
			+ "where airport_code = #{0}"  )
	public void DeleteAirportInfo(String airportCode, String user, Date dt);
    
    @Select("SELECT max(airport_version) FROM t_airport_info")
    public int selectMaxAirportVersion();
    
    @SelectProvider(type = SqlUtils.class, method = "AirportSelectCountByInput")
	public int getCountByInput(String airportcode, String province, String airportname);
	
	@SelectProvider(type = SqlUtils.class, method = "AirportSelectListByInput")
	public List<AirportInfo> selectListByInput(String airportcode, String province, String airportname, int limit, int offset);

}